package com.guoxin.concurrentcy.chapter4;

/**
 * daemon thread
 *
 * @author guoxin
 * @date 2019/7/2
 */
@SuppressWarnings("all")
public class DaemonThread2 {

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            System.out.println("T thread running.");
            Thread innerThread = new Thread() {
                @Override
                public void run() {
                    try {
                        System.out.println("Inner thread running.");
                        Thread.sleep(100_000);
                        System.out.println("Inner thread done.");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            };
            innerThread.setDaemon(true);
            innerThread.start();

            try {
                Thread.sleep(1_000);
                System.out.println("T thread finish done.");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t.setDaemon(true);
        t.start();
        Thread.sleep(1_000);
        System.out.println(Thread.currentThread().getName() + " finish done.");
    }
}
